<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>唐诗小闯关</title>
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Ma Shan Zheng', cursive, 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
            color: #333;
        }

        /* 宣纸纹理背景 */
        .container {
            background-color: #fff9e6;
            background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23e8e8e8' fill-opacity='0.2' fill-rule='evenodd'/%3E%3C/svg%3E");
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            width: 90%;
            max-width: 800px;
            padding: 30px;
            position: relative;
            overflow: hidden;
            transition: transform 0.5s ease;
        }

        /* 毛笔字标题 */
        .title {
            font-size: 2.5rem;
            color: #e74c3c;
            text-align: center;
            margin-bottom: 20px;
            text-shadow: 3px 3px 0px rgba(0, 0, 0, 0.1);
            background: linear-gradient(to right, #e74c3c, #f39c12);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            position: relative;
        }

        .title::after {
            content: "";
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 100px;
            height: 4px;
            background: linear-gradient(to right, #e74c3c, #f39c12);
            border-radius: 2px;
        }

        /* 进度显示 */
        .progress {
            text-align: center;
            font-size: 1.2rem;
            color: #7f8c8d;
            margin-bottom: 20px;
        }

        /* 诗人插画 */
        .poet-image {
            width: 120px;
            height: 120px;
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            position: absolute;
            top: 20px;
            right: 20px;
            opacity: 0.9;
        }

        /* 诗句场景插画 */
        .scene-image {
            width: 150px;
            height: 150px;
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            margin: 0 auto 20px;
        }

        /* 诗词内容 */
        .poem-container {
            margin: 30px 0;
            text-align: center;
            position: relative;
        }

        .poem-title {
            font-size: 1.8rem;
            color: #2c3e50;
            margin-bottom: 15px;
        }

        .poem-author {
            font-size: 1.2rem;
            color: #7f8c8d;
            margin-bottom: 20px;
            font-style: italic;
        }

        .poem-content {
            font-size: 1.5rem;
            line-height: 2.5rem;
            margin-bottom: 30px;
        }

        /* 云朵形状输入框 */
        .blank-input {
            display: inline-block;
            min-width: 80px;
            height: 50px;
            padding: 5px 15px;
            margin: 0 5px;
            border: none;
            background-color: #fff;
            border-radius: 50px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            font-size: 1.2rem;
            text-align: center;
            outline: none;
            transition: all 0.3s ease;
            position: relative;
            transform: scale(1);
        }

        .blank-input:focus {
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.5);
            transform: scale(1.05);
        }

        .blank-input.correct {
            background-color: #d5f5e3;
            box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.5);
        }

        .blank-input.wrong {
            background-color: #fadbd8;
            box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.5);
        }

        /* 对勾动画 */
        .check-mark {
            position: absolute;
            right: -25px;
            top: 50%;
            transform: translateY(-50%);
            color: #27ae60;
            font-size: 1.5rem;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .correct .check-mark {
            opacity: 1;
            animation: bounceIn 0.5s ease;
        }

        @keyframes bounceIn {
            0% { transform: translateY(-50%) scale(0.5); opacity: 0; }
            50% { transform: translateY(-50%) scale(1.2); }
            100% { transform: translateY(-50%) scale(1); opacity: 1; }
        }

        /* 错误提示 */
        .error-hint {
            color: #e74c3c;
            font-size: 1rem;
            margin-top: 5px;
            display: none;
        }

        .wrong + .error-hint {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        /* 按钮样式 */
        .btn {
            padding: 12px 25px;
            margin: 10px;
            border: none;
            border-radius: 50px;
            font-size: 1.2rem;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .btn-primary {
            background-color: #3498db;
            color: white;
        }

        .btn-primary:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
        }

        .btn-hint {
            background-color: #f39c12;
            color: white;
        }

        .btn-hint:hover {
            background-color: #e67e22;
            transform: translateY(-2px);
        }

        .btn-restart {
            background-color: #2ecc71;
            color: white;
        }

        .btn-restart:hover {
            background-color: #27ae60;
            transform: translateY(-2px);
        }

        /* 按钮容器 */
        .button-container {
            display: flex;
            justify-content: center;
            margin-top: 30px;
            flex-wrap: wrap;
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 100;
            justify-content: center;
            align-items: center;
        }

        .modal-content {
            background-color: white;
            padding: 30px;
            border-radius: 15px;
            max-width: 80%;
            text-align: center;
            animation: modalFadeIn 0.3s ease;
            position: relative;
        }

        @keyframes modalFadeIn {
            from { opacity: 0; transform: scale(0.9); }
            to { opacity: 1; transform: scale(1); }
        }

        .modal-title {
            font-size: 1.8rem;
            color: #2ecc71;
            margin-bottom: 15px;
        }

        .modal-text {
            font-size: 1.2rem;
            margin-bottom: 20px;
            color: #34495e;
        }

        .modal-fact {
            font-style: italic;
            color: #7f8c8d;
            margin: 20px 0;
            padding: 10px;
            background-color: #f8f9fa;
            border-radius: 10px;
        }

        .close-modal {
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 1.5rem;
            color: #7f8c8d;
            cursor: pointer;
        }

        /* 证书样式 */
        .certificate {
            display: none;
            background-color: #fff9e6;
            padding: 30px;
            border: 10px solid #f1c40f;
            border-radius: 15px;
            text-align: center;
            max-width: 90%;
            margin: 20px auto;
        }

        .certificate-title {
            font-size: 2rem;
            color: #e74c3c;
            margin-bottom: 20px;
        }

        .certificate-text {
            font-size: 1.2rem;
            margin-bottom: 15px;
        }

        .certificate-score {
            font-size: 1.5rem;
            color: #27ae60;
            margin: 20px 0;
        }

        .stamp {
            width: 100px;
            height: 100px;
            background-color: #e74c3c;
            color: white;
            border-radius: 50%;
            display: inline-flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5rem;
            transform: rotate(-15deg);
            margin: 20px 0;
            border: 3px dashed white;
        }

        /* 翻页动画 */
        .page-turn {
            animation: pageTurn 0.5s ease;
        }

        @keyframes pageTurn {
            0% { transform: rotateY(0deg); opacity: 1; }
            50% { transform: rotateY(90deg); opacity: 0; }
            100% { transform: rotateY(0deg); opacity: 1; }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .title {
                font-size: 2rem;
            }
            
            .poem-content {
                font-size: 1.3rem;
                line-height: 2rem;
            }
            
            .blank-input {
                min-width: 60px;
                height: 40px;
                font-size: 1rem;
            }
            
            .poet-image {
                width: 80px;
                height: 80px;
                top: 10px;
                right: 10px;
            }
            
            .scene-image {
                width: 120px;
                height: 120px;
            }
        }
    </style>
    <link href="https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&display=swap" rel="stylesheet">
</head>
<body>
    <div class="container" id="game-container">
        <h1 class="title">唐诗小闯关</h1>
        <div class="progress" id="progress">第 1 关 / 共 5 关</div>
        
        <div class="poet-image" id="poet-image"></div>
        <div class="scene-image" id="scene-image"></div>
        
        <div class="poem-container">
            <h2 class="poem-title" id="poem-title">静夜思</h2>
            <p class="poem-author" id="poem-author">唐 · 李白</p>
            <div class="poem-content" id="poem-content">
                <!-- 诗句将通过JS动态生成 -->
            </div>
        </div>
        
        <div class="button-container">
            <button class="btn btn-hint" id="hint-btn">提示</button>
            <button class="btn btn-primary" id="next-btn" disabled>下一关</button>
        </div>
    </div>
    
    <!-- 完成一关的弹窗 -->
    <div class="modal" id="success-modal">
        <div class="modal-content">
            <span class="close-modal" id="close-modal">&times;</span>
            <h3 class="modal-title">你太厉害啦！</h3>
            <p class="modal-text" id="success-text"></p>
            <p class="modal-fact" id="fun-fact"></p>
            <button class="btn btn-primary" id="continue-btn">继续闯关</button>
        </div>
    </div>
    
    <!-- 完成所有关卡的证书 -->
    <div class="container certificate" id="certificate">
        <h2 class="certificate-title">唐诗小达人</h2>
        <p class="certificate-text">恭喜你完成了所有唐诗挑战！</p>
        <p class="certificate-text">你展现了出色的诗词天赋</p>
        <div class="certificate-score" id="final-score">得分: 10/10</div>
        <div class="stamp">优秀</div>
        <button class="btn btn-restart" id="restart-btn">再来一次</button>
    </div>

    <script>
        // 唐诗数据
        const poems = [
            {
                title: "静夜思",
                author: "李白",
                content: "床前明月光，疑是地上霜。举头望明月，低头思故乡。",
                blanks: ["明月光", "地上霜", "思故乡"],
                scene: "moon", // 场景标识
                successText: "你完成了《静夜思》！这首诗藏着思乡的秘密哦～",
                funFact: "你知道吗？李白写这首诗时正在外地旅行，看到月亮想起了家乡。"
            },
            {
                title: "春晓",
                author: "孟浩然",
                content: "春眠不觉晓，处处闻啼鸟。夜来风雨声，花落知多少。",
                blanks: ["不觉晓", "闻啼鸟", "知多少"],
                scene: "spring",
                successText: "太棒了！你学会了《春晓》！",
                funFact: "有趣的是：孟浩然写这首诗时，是被窗外的鸟叫声吵醒的呢！"
            },
            {
                title: "悯农",
                author: "李绅",
                content: "锄禾日当午，汗滴禾下土。谁知盘中餐，粒粒皆辛苦。",
                blanks: ["日当午", "禾下土", "皆辛苦"],
                scene: "farm",
                successText: "真厉害！你记住了《悯农》！",
                funFact: "小知识：李绅写这首诗是为了告诉人们粮食来之不易。"
            },
            {
                title: "登鹳雀楼",
                author: "王之涣",
                content: "白日依山尽，黄河入海流。欲穷千里目，更上一层楼。",
                blanks: ["依山尽", "入海流", "一层楼"],
                scene: "tower",
                successText: "恭喜！你掌握了《登鹳雀楼》！",
                funFact: "你知道吗？鹳雀楼是中国四大名楼之一，在山西省。"
            },
            {
                title: "咏鹅",
                author: "骆宾王",
                content: "鹅，鹅，鹅，曲项向天歌。白毛浮绿水，红掌拨清波。",
                blanks: ["向天歌", "浮绿水", "拨清波"],
                scene: "goose",
                successText: "太棒了！你学会了《咏鹅》！",
                funFact: "有趣的是：骆宾王写这首诗时只有7岁，是唐代的小神童！"
            }
        ];

        // 场景图片数据
        const sceneImages = {
            moon: "https://img.icons8.com/color/96/000000/full-moon.png",
            spring: "https://img.icons8.com/color/96/000000/spring.png",
            farm: "https://img.icons8.com/color/96/000000/rice-field.png",
            tower: "https://img.icons8.com/color/96/000000/castle.png",
            goose: "https://img.icons8.com/color/96/000000/duck.png"
        };

        // 诗人图片数据
        const poetImages = {
            "李白": "https://img.icons8.com/color/96/000000/confucius.png",
            "孟浩然": "https://img.icons8.com/color/96/000000/confucius.png",
            "李绅": "https://img.icons8.com/color/96/000000/confucius.png",
            "王之涣": "https://img.icons8.com/color/96/000000/confucius.png",
            "骆宾王": "https://img.icons8.com/color/96/000000/confucius.png"
        };

        // 游戏状态
        let currentPoemIndex = 0;
        let score = 0;
        let totalBlanks = 0;
        let hintUsed = false;

        // DOM元素
        const gameContainer = document.getElementById('game-container');
        const progressText = document.getElementById('progress');
        const poetImage = document.getElementById('poet-image');
        const sceneImage = document.getElementById('scene-image');
        const poemTitle = document.getElementById('poem-title');
        const poemAuthor = document.getElementById('poem-author');
        const poemContent = document.getElementById('poem-content');
        const hintBtn = document.getElementById('hint-btn');
        const nextBtn = document.getElementById('next-btn');
        const successModal = document.getElementById('success-modal');
        const successText = document.getElementById('success-text');
        const funFact = document.getElementById('fun-fact');
        const continueBtn = document.getElementById('continue-btn');
        const closeModal = document.getElementById('close-modal');
        const certificate = document.getElementById('certificate');
        const finalScore = document.getElementById('final-score');
        const restartBtn = document.getElementById('restart-btn');

        // 初始化游戏
        function initGame() {
            currentPoemIndex = 0;
            score = 0;
            loadPoem(currentPoemIndex);
        }

        // 加载诗词
        function loadPoem(index) {
            hintUsed = false;
            hintBtn.disabled = false;
            nextBtn.disabled = true;
            
            const poem = poems[index];
            poemTitle.textContent = poem.title;
            poemAuthor.textContent = `唐 · ${poem.author}`;
            
            // 设置诗人图片
            poetImage.style.backgroundImage = `url(${poetImages[poem.author]})`;
            
            // 设置场景图片
            sceneImage.style.backgroundImage = `url(${sceneImages[poem.scene]})`;
            
            // 更新进度
            progressText.textContent = `第 ${index + 1} 关 / 共 ${poems.length} 关`;
            
            // 清空诗句容器
            poemContent.innerHTML = '';
            
            // 分割诗句
            const lines = poem.content.split(/[，。；]/).filter(line => line.trim() !== '');
            
            // 处理每一行诗句
            lines.forEach(line => {
                const lineDiv = document.createElement('div');
                lineDiv.style.marginBottom = '15px';
                
                // 检查这一行是否有填空
                const hasBlank = poem.blanks.some(blank => line.includes(blank));
                
                if (hasBlank) {
                    // 处理有填空的行
                    let processedLine = line;
                    
                    // 替换填空部分为输入框
                    poem.blanks.forEach(blank => {
                        if (line.includes(blank)) {
                            const blankIndex = processedLine.indexOf(blank);
                            const beforeBlank = processedLine.substring(0, blankIndex);
                            const afterBlank = processedLine.substring(blankIndex + blank.length);
                            
                            processedLine = `
                                ${beforeBlank}
                                <span class="blank-container" style="display: inline-block; position: relative;">
                                    <input type="text" class="blank-input" data-answer="${blank}" 
                                        maxlength="${blank.length}">
                                    <span class="check-mark">✓</span>
                                </span>
                                <div class="error-hint">再想想～</div>
                                ${afterBlank}
                            `;
                        }
                    });
                    
                    lineDiv.innerHTML = processedLine;
                } else {
                    // 没有填空的行直接显示
                    lineDiv.textContent = line;
                }
                
                poemContent.appendChild(lineDiv);
            });
            
            // 添加输入框事件监听
            const blankInputs = document.querySelectorAll('.blank-input');
            blankInputs.forEach(input => {
                input.addEventListener('input', checkAnswer);
            });
            
            // 添加翻页动画
            gameContainer.classList.add('page-turn');
            setTimeout(() => {
                gameContainer.classList.remove('page-turn');
            }, 500);
        }

        // 检查答案
        function checkAnswer(e) {
            const input = e.target;
            const answer = input.getAttribute('data-answer');
            const container = input.parentElement;
            const errorHint = container.nextElementSibling;
            
            if (input.value === answer) {
                // 答案正确
                input.classList.add('correct');
                input.classList.remove('wrong');
                errorHint.style.display = 'none';
                score++;
            } else if (input.value.length === answer.length) {
                // 答案错误
                input.classList.add('wrong');
                input.classList.remove('correct');
            } else {
                // 输入不完整
                input.classList.remove('correct', 'wrong');
                errorHint.style.display = 'none';
            }
            
            // 检查是否所有填空都完成了
            checkCompletion();
        }

        // 检查是否完成当前诗词
        function checkCompletion() {
            const blankInputs = document.querySelectorAll('.blank-input');
            const allFilled = Array.from(blankInputs).every(input => input.value.length === input.getAttribute('data-answer').length);
            const allCorrect = Array.from(blankInputs).every(input => input.value === input.getAttribute('data-answer'));
            
            if (allFilled) {
                if (allCorrect) {
                    // 全部正确，显示成功弹窗
                    showSuccessModal();
                }
                nextBtn.disabled = false;
            } else {
                nextBtn.disabled = true;
            }
        }

        // 显示成功弹窗
        function showSuccessModal() {
            const poem = poems[currentPoemIndex];
            successText.textContent = poem.successText;
            funFact.textContent = poem.funFact;
            successModal.style.display = 'flex';
        }

        // 下一关
        function nextPoem() {
            currentPoemIndex++;
            
            if (currentPoemIndex < poems.length) {
                loadPoem(currentPoemIndex);
            } else {
                // 所有关卡完成，显示证书
                showCertificate();
            }
            
            successModal.style.display = 'none';
        }

        // 显示证书
        function showCertificate() {
            gameContainer.style.display = 'none';
            certificate.style.display = 'block';
            
            // 计算总分
            totalBlanks = poems.reduce((sum, poem) => sum + poem.blanks.length, 0);
            finalScore.textContent = `得分: ${score}/${totalBlanks}`;
        }

        // 提示功能
        function giveHint() {
            if (hintUsed) return;
            
            const blankInputs = document.querySelectorAll('.blank-input');
            const emptyInputs = Array.from(blankInputs).filter(input => input.value.length === 0);
            
            if (emptyInputs.length > 0) {
                const randomInput = emptyInputs[Math.floor(Math.random() * emptyInputs.length)];
                const answer = randomInput.getAttribute('data-answer');
                randomInput.value = answer.charAt(0);
                randomInput.focus();
                
                hintUsed = true;
                hintBtn.disabled = true;
                
                // 检查完成状态
                checkCompletion();
            }
        }

        // 重新开始游戏
        function restartGame() {
            certificate.style.display = 'none';
            gameContainer.style.display = 'block';
            initGame();
        }

        // 事件监听
        nextBtn.addEventListener('click', nextPoem);
        hintBtn.addEventListener('click', giveHint);
        continueBtn.addEventListener('click', () => {
            successModal.style.display = 'none';
            nextPoem();
        });
        closeModal.addEventListener('click', () => {
            successModal.style.display = 'none';
        });
        restartBtn.addEventListener('click', restartGame);

        // 点击模态框外部关闭
        successModal.addEventListener('click', (e) => {
            if (e.target === successModal) {
                successModal.style.display = 'none';
            }
        });

        // 初始化游戏
        initGame();
    </script>
</body>
</html>
